
package net.ocps.tchs.GovSim;

import java.awt.Font;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class GameMenu implements Screen {
        screenSwitcher game;
        private OrthographicCamera camera;
        private SpriteBatch batch;
        private Texture texture;
        private Sprite sprite;
        private Stage stage;
        private TextureAtlas atlas;
        private Skin skin;
        private Table table;
        private TextButton buttonExit,buttonPlay;
        private TextButtonStyle Style;
        private BitmapFont font;
         public GameMenu(screenSwitcher game) {
          this.game = game;
                float w = Gdx.graphics.getWidth();
                float h = Gdx.graphics.getHeight();
        font = new BitmapFont();
                camera = new OrthographicCamera(1, h/w);
                batch = new SpriteBatch();
                
                texture = new Texture(Gdx.files.internal("ui/Usmap.jpeg"));
                texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
                
                TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);
                
                sprite = new Sprite(region);
                sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
                sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
                sprite.setPosition(-sprite.getWidth()/2, -sprite.getHeight()/2);
         }
        @Override
        public void render(float delta) {
                Gdx.gl.glClearColor(0, 0, 0, 1);
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                
           		batch.begin();
        		batch.draw(texture, 0, 0);
        		batch.end();
               stage.act(delta);
               stage.draw();
                
                
            
        }

        @Override
        public void resize(int width, int height) {
                // TODO Auto-generated method stub
                
        }

        @Override
        public void show() {


                 stage = new Stage();
             
                Gdx.input.setInputProcessor(stage);
                
                atlas = new TextureAtlas(Gdx.files.internal("ui/button.pack"));
                
                skin = new Skin(atlas);
                
                table = new Table(skin);
                table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
                TextButtonStyle Style = new TextButtonStyle();
                Style.up = skin.getDrawable("button.up");
                Style.down = skin.getDrawable("button.down");
                Style.pressedOffsetX = 1;
                Style.pressedOffsetY = -1;
                Style.font = font;
                
                buttonPlay = new TextButton("Play",Style);
                buttonPlay.pad(20);
                buttonExit = new TextButton("Exit", Style);
                buttonExit.pad(20);
                                
               buttonExit.addListener( new ClickListener() {
            	   @Override
            	    public void clicked(InputEvent event, float x, float y) {
            	       Gdx.app.exit();
            	    };
            	});
               
               buttonPlay.addListener( new ClickListener() {
            	   @Override
            	    public void clicked(InputEvent event, float x, float y) {
            		   game.setScreen(new gameBoard(game));
            	    };
            	});


               
                  
                table.debug();
                table.add(buttonPlay);
                table.add(buttonExit);
       
                table.pad(20);
               
                
                stage.addActor(table);
                
            
                                
        }

        @Override
        public void hide() {
        	dispose();
        }

        @Override
        public void pause() {
                // TODO Auto-generated method stub
                
        }

        @Override
        public void resume() {
                // TODO Auto-generated method stub
                
        }

        @Override
        public void dispose() {
                // TODO Auto-generated method stub
            batch.dispose();
 	       skin.dispose();
 	       atlas.dispose();
 	       stage.dispose();
 	       buttonPlay.remove();
 	       buttonExit.remove();
 	       table.remove();
 	       
 	       
 	       System.out.println("disposed");
        }

}